﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XProject.DataVisit.Model;
using System.Web;
using XProject.DataVisit.Factory;
using XProject.DataVisit.Model.Flow;
using XProject.DataVisit.Model.Doc;
using System.IO;

namespace XProject.DataVisit.Handler.View.Flow
{
    public class FlowView:AbstractView
    {
        private UserInfo CurrentUser;
        public override void init()
        {
            if (HttpContext.Current.Session["UserInfo"] != null)
            {
                CurrentUser = HttpContext.Current.Session["UserInfo"] as UserInfo;
                base.init();
            }
            else
            {
                return;
            }
        }

        #region 流程定制
        public void GetBaseFlow()
        {
            JsonResponse.ResponseObject = DaoFactory.FlowNameDao.GetAll();
        }

        public void AddBaseFlow()
        {
            var flow = JsonRequest.GetParam<FlowName>("info");
            flow.LastUpdate = DateTime.Now;
            flow.Creater = CurrentUser.PID;
            JsonResponse.ResponseObject = DaoFactory.FlowNameDao.Save(flow);
        }

        public void DelBaseFlow()
        {
            var flow = JsonRequest.GetParam<FlowName>("info");
            JsonResponse.ResponseObject = DaoFactory.FlowNameDao.Delete(flow);
        }



        public void GetNodeFlow()
        {
            var id = JsonRequest.GetParam<Guid>("id");
            JsonResponse.ResponseObject = DaoFactory.FlowNodeDao.GetNodeList(id);
        }

        public void AddNodeFlow()
        {
            var flow = JsonRequest.GetParam<FlowNode>("info");
            flow.LastUpdate = DateTime.Now;
            flow.Creater = CurrentUser.PID;
            JsonResponse.ResponseObject = DaoFactory.FlowNodeDao.Save(flow);
        }

        public void DelNodeFlow()
        {
            var flow = JsonRequest.GetParam<FlowNode>("info");
            JsonResponse.ResponseObject = DaoFactory.FlowNodeDao.Delete(flow);
        }
        #endregion


        #region 申请单定制

        public void GetDocInfo()
        {
            var search = JsonRequest.GetParam<DocSearch>("info");
            JsonResponse.ResponseObject = DaoFactory.DocumentInfoDao.GetSearchData(search,CurrentUser.PID);
        }

        public void GetDocInfo_suss()
        {
            var search = JsonRequest.GetParam<DocSearch>("info");
            JsonResponse.ResponseObject = DaoFactory.DocumentInfoDao.GetSearchData_Susse(search);
        }

        public void UpdateDocInfo()
        {
            var info = JsonRequest.GetParam<DocumentInfo>("info");
            JsonResponse.ResponseObject = DaoFactory.DocumentInfoDao.Update(info);
        }

        public void DelDocInfo()
        {
            var info = JsonRequest.GetParam<DocumentInfo>("info");
            File.Delete(HttpContext.Current.Server.MapPath("../../")+info.MoreInfo);
            JsonResponse.ResponseObject = DaoFactory.DocumentInfoDao.Delete(info);
        }

        public void GetDocInfo_All()
        {
            JsonResponse.ResponseObject = DaoFactory.DocumentInfoDao.GetSearchData();
        }
        #endregion
    }
}
